/**
 * Copyright (C) 2010 D. Zoller, M. Richter, M. Blumenstein & W. Biller
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.googlecode.siafu.rest.utils;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

/**
 * Bean for setting up the tcp connection to the siafu tcp command server
 * 
 * @author D. Zoller
 * @version $Id: ServerConfig.java,v 1.7 2010-06-16 08:34:52 nosebrain Exp $
 */
public class ServerConfig extends Properties {
	private static final long serialVersionUID = -1587403607663850051L;

	private static final ServerConfig INSTANCE = new ServerConfig();
	
	private static final String PORT = "port";
	private static final String SERVER = "host";
	
	/**
	 * @return the {@link ServerConfig} instance
	 */
	public static ServerConfig getInstance() {
		return INSTANCE;
	}
	
	/**
	 * constructor deactivated (singleton pattern)
	 */
	protected ServerConfig() {
		
		try {
			this.load(ServerConfig.class.getResourceAsStream("/server.properties"));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * @param port the port to set
	 */
	public void setPort(int port) {
		setProperty(PORT, String.valueOf(port));
	}
	
	/**
	 * @param host the host to set
	 */
	public void setHost(String host) {
		setProperty(PORT, host);
	}
	
	/**
	 * @return the port
	 */
	public int getPort() {
		return Integer.valueOf(getProperty(PORT, "4444"));
	}

	/**
	 * @return the host
	 */
	public String getHost() {
		return getProperty(SERVER, "localhost");
	}
}
